package org.qiuer.func.function.array;

import org.qiuer.ast.expression.function.ArrowFunctionExpression;
import org.qiuer.func.AMemberFunction;
import org.qiuer.run.Context;
import org.qiuer.exception.EValidate;
import org.qiuer.exception.IException;

import java.util.List;

public class ArrayForEachFunction extends AMemberFunction<List> {

  @Override
  public Object run(List member, Context context, Object... args) throws IException {
    ArrowFunctionExpression f = EValidate.cast(args[0], ArrowFunctionExpression.class);
    for (int i = 0; i < member.size(); i++) {
      Object[] tmp = new Object[3];
      tmp[0] = member.get(i);
      tmp[1] = (long) i;
      tmp[2] = member;
      f.run(context, tmp);
      // item, index
//      function._run(context, member.get(i), i);
    }
    return null;
  }

  @Override
  public String getName() {
    return "forEach";
  }
}
